
<template name="sendcar">
	<!-- 物资单列表 做申请单 -->
	<view class="mypage">
		<view class="cu-bar search bg-white">
			<view class="search-form round">
				<text class="cuIcon-search"></text>
				<input type="text" placeholder="输入物资单号" v-model="keyword" />
			</view>
			<view class="action">
				<button class="cu-btn bg-blue shadow-blur round" @tap="handelSearch">搜索</button>
			</view>
		</view>

		<view class="card-list-wrapper">
			<view class="card-list-row radius shadow-warp bg-white margin-top" v-for="(item,index) in planList" :key="index"
			 @click="openDetail(index)">

				<view class="flex-just-between bottom-border top-wrap">
					<text class="text-blue text-bold">单号：{{ item.BILLNO || item.PK_MATERIAL }}</text>
					<view class="cu-capsule radius">
						<view class='cu-tag bg-blue sm'>
							<text class='cuIcon-medal'></text>
						</view>
						<view class="cu-tag line-brown sm">
							{{ index+1}}
						</view>
					</view>
				</view>

				<view class="card-list-row-1 margin-top">
					<text class="cuIcon-title text-red"></text>
					<text>名称：{{ item.VNAME || item.MATERIALNAME }}</text>

				</view>

				<view class="card-list-row-1">
					<text class="cuIcon-title text-orange"></text>
					<text>规格：{{ item.MATCLASSNAME  || item.MATSPEC }} </text>
					<text class="text-blue">&emsp; {{ item.NNUMSQ || '' }}&emsp;</text> |
					<!-- <text class="text-red">&emsp;￥{{ '32.00'}}</text> -->
				</view>

				<view class="position-a checkFlag" v-if="item.ischeck">
					<text class='cuIcon-squarecheckfill text-blue'></text>
				</view>

				<!-- <view class="flex-just-between top-border margin-top btn-wrap">
					<button class="cu-btn round lines-gray" >出库</button>
					<button class="cu-btn round lines-gray" >移位</button>
				</view> -->

			</view>

		</view>

		<view class="next-btn-wrap position-f" @click="nextTap">
			<button class="big-btn bg-green shadow-blur">
				<text class="cuIcon-refresharrow text-bold"></text>
			</button>
		</view>
	</view>

</template>

<script>
	import {
		mapState,
		mapMutations
	} from 'vuex'
	import api from '@/common/api.js';
	import utils from '@/common/util.js';
	let query = {
		"category": "BD_MATERIAL",
		"page": 1,
		"rows": "10",
		"sidx": "",
		"sord": "",
		"queryJson": {},
		"userId": "",
		"account": "admin"
	}
	let _self, menuType, page = 1,
		total = 1,
		queryJson = {
			BILLNO: '',
			BTYPE:3
		};
	export default {
		computed: mapState(['userInfo', 'baseUrl']),
		data() {
			return {
				planList: [],
				keyword: ''
			};
		},

		onLoad(p) {
			// console.log(p)
			_self = this
			menuType = p.sqlTbName
			query.category = 'ST_STOCKINFO' // 吨包水泥库存物资
			query.userId = _self.userInfo.UserId
			query.account = _self.userInfo.Account
			this.getList()
		},
		//下拉刷新
		onPullDownRefresh: function() {
			// 重置分页及数据
			page = 1;
			total = 1;
			this.getList();
			setTimeout(function() {
				uni.stopPullDownRefresh();
			}, 1000);
			uni.showToast({
				"title": "数据已刷新",
				icon: "none"
			});
		},
		// 加载更多
		onReachBottom: function() {
			this.getList();
		},
		methods: {
			openDetail: function(e) {
				_self.planList[e].ischeck = !_self.planList[e].ischeck;
			},
			handelSearch() {
				queryJson.BILLNO = _self.keyword;
				query.queryJson = JSON.stringify(queryJson);
				// console.log(_self.keyword);
				// console.log(query);
				page = 1;
				total = 1;
				_self.planList = [];
				this.getList();
			},
			nextTap() {
				let t = [];
				_self.planList.forEach((item) => {
					if (item.ischeck) {
						t.push(item)
					}
				});
				// uni.$emit('selectMat', {list:'55' } );
				let uu = '/pages/tab01/d-outbound/submit-manual?data=';
				
				uni.navigateTo({
					url: uu + encodeURIComponent(JSON.stringify(t))
				})
				// uni.$emit('update',{msg:'页面更新'})	
			},
			getList() {
				console.log(query);
				if (page > total) {
					return utils.tips('没有数据了')
				}
				this.axios({
					url: api.apiPublic.getMaterList ,
					data: query ,
					isLoading: 1
				}).then(res=>{
					let { Result } = res ;
					let array = Result.rows.map((item) => {
						item.ischeck = false;
						return item;
					})
					if (page == 1) {
						_self.planList = array
						if (_self.planList.length == 0) {
							utils.tips('暂无数据！');
						}
						_self.setPageTitle('物资单列表(' + Result.records + ')')
					} else {
						_self.planList = _self.planList.concat(array)
					}
					total = Result.total
					page++
					_self.planList = array
				})
			},
			setPageTitle(d) {
				uni.setNavigationBarTitle({
					title: d
				});
			},
		}
	}
</script>

<style scoped>
	.height50 {
		height: 50px;
	}

	.card-list-wrapper {
		width: 710upx;
		height: 100upx;
		margin: 0 auto;

	}

	.card-list-row {
		padding: 20upx;
	}

	.card-list-row-1 {
		padding: 10upx 0;
	}

	.top-border {
		border-top: 1upx solid rgba(0, 0, 0, .1);
	}

	.top-wrap {
		padding-bottom: 20upx;
	}

	.bottom-border {
		border-bottom: 1upx solid rgba(0, 0, 0, .1);
	}

	.btn-wrap {
		padding-top: 20upx;
	}

	.checkFlag {
		top: 50%;
		right: 20upx;
		font-size: 40upx;
	}

	.next-btn-wrap {
		position: fixed;
		right: 50upx;
		bottom: 100upx;
	}

	.big-btn {
		width: 100upx;
		height: 100upx;
		border-radius: 50upx;
		font-size: 40upx;
	}
</style>
